package com.interview.a_多线程.c_停止线程.e_停止线程_错误方法.a_stop方法;

/**
 * stop 会使单元任务无法完成，破坏数据
 */

public class StopThread implements Runnable {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new StopThread());
        thread.start();

        //执行0.5秒时中断
        Thread.sleep(1200);
        thread.stop();
        System.out.println("前往战场....");
    }

    @Override
    public void run() {
        System.out.println("军队的士兵们开始申领枪械.........");

        for (int i = 0; i < 10; i++) {
            System.out.println("军队：" + i + "开始领取装备");
            for (int j = 0; j < 10; j++) {
                System.out.println("士兵" + j + "获取完成");
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("军队" + i + "领取完毕 \n\n");
        }
        System.out.println("任务运行结束...  当前 interrupt=" + Thread.currentThread().isInterrupted());
    }

}
